package org.example.enums;

import lombok.Getter;

/**
 * 部署任务步骤枚举
 */
@Getter
public enum EDeployTaskStep implements ITaskStep {

    START(0, "start","开始",0),
    CHECKHEALTH(10, "agentCheckHealth","agent健康检查",10),
    DISKCHECK(20,"diskCheck","磁盘检查",20),
    COPY(30, "copy","文件复制",40),
    UNZIP(40, "unzip","文件解压",60),
    ENVCONFIG(50, "envConfig","环境配置",80),
    FILECONFIG(60, "fileConfig","文件配置",90),
    END(70, "end","完成",100);

    private int stepNum;
    private String name;
    private String cnName;
    private int process;

    EDeployTaskStep(int stepNum, String name,String cnName,int process) {
        this.stepNum = stepNum;
        this.name = name;
        this.cnName = cnName;
        this.process = process;
    }

    public int getStepNum() {
        return stepNum;
    }

    public EDeployTaskStep getLastStepNum() {
        int step = stepNum > DISKCHECK.getStepNum() ? stepNum - 10 : EDeployTaskStep.CHECKHEALTH.getStepNum();
        return EDeployTaskStep.getByStepNum(step);
    }

    @Override
    public EDeployTaskStep getNextStepNum() {
        int step = stepNum < FILECONFIG.getStepNum() ? stepNum + 10 : EDeployTaskStep.END.getStepNum();
        return EDeployTaskStep.getByStepNum(step);
    }

    public String getName() {
        return name;
    }

    public String getCnName() {
        return cnName;
    }

    /**
     * 根据步骤号获取步骤枚举
     *
     * @param stepNum stepNum
     * @return ETaskStep
     */
    public static EDeployTaskStep getByStepNum(int stepNum) {
        EDeployTaskStep rs = null;
        for (EDeployTaskStep step : EDeployTaskStep.values()) {
            if (step.getStepNum() == stepNum) {
                rs = step;
                break;
            }
        }
        if (rs == null) throw new RuntimeException("EDeployTaskStep 步骤号错误");
        return rs;
    }

    @Override
    public ITaskStep getStep() {
        return EDeployTaskStep.getByStepNum(getStepNum());
    }
}
